import { useI18n } from '/@/hooks/web/useI18n';
import { BasicColumn, BasicTableProps, FormProps } from '/@/components/Table';
import { cusFpApplyKpListData } from '/@/api/shop/order/cusFpApply';

const { t } = useI18n('shop.order.cusFpApply');

const modalProps = {
  title: t('开票选择'),
};

const searchForm: FormProps = {
  baseColProps: { lg: 6, md: 8 },
  labelWidth: 80,
  schemas: [
    {
      label: t('客户编码'),
      field: 'cusCode',
      component: 'Input',
      show: false,
    },
    {
      label: t('申请时间'),
      field: 'createDate',
      component: 'RangePicker',
    },

    {
      label: t('申请人'),
      field: 'createBy',
      component: 'Input',
    },
    {
      label: t('开票状态'),
      field: 'kpStatus',
      component: 'Select',
      componentProps: {
        dictType: 'cus_fp_status',
        allowClear: true,
      },
    },
    {
      label: t('开票完成'),
      field: 'overDate',
      component: 'RangePicker',
      componentProps: {
        format: 'YYYY-MM-DD',
        showTime: false,
      },
    },
    {
      label: t('申请备注'),
      field: 'remarks',
      component: 'Input',
    },
    {
      label: t('状态'),
      field: 'status',
      component: 'Select',
      componentProps: {
        dictType: 'bpm_biz_status',
        allowClear: true,
      },
    },
  ],
  fieldMapToTime: [
    ['createDate', ['createDate_gte', 'createDate_lte']],
    ['overDate', ['overDate_gte', 'overDate_lte']],
  ],
};

const tableColumns: BasicColumn[] = [
  {
    title: t('订单号'),
    dataIndex: 'soMain.code',
    key: 'a.order_code',
    sorter: true,
    width: 150,
    align: 'center',
  },
  {
    title: t('订单日期'),
    dataIndex: 'soMain.ddate',
    key: 'soMain.ddate',
    sorter: true,
    width: 100,
    align: 'center',
  },
  {
    title: t('存货编码'),
    dataIndex: 'basInv.cinvcode',
    key: 'a.inv_code',
    sorter: true,
    width: 120,
    align: 'left',
  },
  {
    title: t('存货名称'),
    dataIndex: 'basInv.cinvname',
    key: 'inv.cinvname',
    sorter: true,
    width: 180,
    align: 'left',
  },
  {
    title: t('规格型号'),
    dataIndex: 'basInv.cinvstd',
    key: 'inv.cinvstd',
    sorter: true,
    width: 100,
    align: 'left',
  },
  {
    title: t('单位'),
    dataIndex: 'basInv.unitName',
    key: 'inv.unit_name',
    sorter: true,
    width: 70,
    align: 'left',
  },
  {
    title: t('销售数量'),
    dataIndex: 'soRds.iquantity',
    key: 'a.iquantity',
    sorter: true,
    width: 120,
    align: 'center',
  },
  {
    title: t('单价'),
    dataIndex: 'iprice',
    key: 'a.itaxunitprice',
    sorter: false,
    width: 120,
    align: 'right',
  },
  {
    title: t('销售金额'),
    dataIndex: 'soRds.isum',
    key: 'a.isum',
    sorter: true,
    width: 120,
    align: 'center',
  },
  {
    title: t('折扣额'),
    dataIndex: 'soRds.isum',
    key: 'a.isum',
    sorter: true,
    width: 80,
    align: 'center',
  },
  {
    title: t('已开数量'),
    dataIndex: 'soRds.kpQty',
    key: 'a.kp_qty',
    sorter: false,
    width: 120,
    align: 'center',
  },
  {
    title: t('已开金额'),
    dataIndex: 'soRds.kpSum',
    key: 'a.isum',
    sorter: false,
    width: 120,
    align: 'center',
  },

  {
    title: t('已开折扣'),
    dataIndex: 'soRds.kpSaleSum',
    key: 'a.kp_sale_sum',
    sorter: false,
    width: 120,
    align: 'center',
  },
  {
    title: t('剩余数量'),
    dataIndex: 'sykpQty',
    sorter: false,
    width: 100,
    align: 'center',
    fixed: 'right',
  },
  {
    title: t('剩余金额'),
    dataIndex: 'sykpSum',
    sorter: false,
    width: 100,
    align: 'center',
    fixed: 'right',
  },
  {
    title: t('剩余折扣'),
    dataIndex: 'sykpSaleSum',
    sorter: false,
    width: 100,
    align: 'center',
    fixed: 'right',
  },
];

const tableProps: BasicTableProps = {
  api: cusFpApplyKpListData,
  beforeFetch: (params) => {
    params['isAll'] = true;
    return params;
  },
  columns: tableColumns,
  formConfig: searchForm,
  rowKey: 'sodid',
};

export default {
  modalProps,
  tableProps,
  itemCode: 'sodid',
  // itemName: 'cinvname',
};
